package models

import com.db4o.activation.{ActivationPurpose, Activator}
import com.db4o.ta.Activatable

trait Activable extends Activatable {
  
  @transient
  var activator:Activator = null
  
  def bind(activator:Activator) {
    if (this.activator == activator) {
      Unit
    }
    if (activator != null && null != this.activator) {
      throw new IllegalStateException("Object can only be bound to one activator");
    }
    this.activator = activator;
  }
  
  def activate(activationPurpose:ActivationPurpose) {
    if(null!=activator){
      activator.activate(activationPurpose);
    }
  }
}